package GUI.MenuPrincipal;

import java.rmi.RemoteException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import service.article.exceptions.ProxyException;
import GUI.Administracion.AgregarCategoria;
import GUI.Cocina.MainCocina;
import GUI.Productos.MainProductos;
import GUI.Ventas.MenuVentas;

public class Main extends Shell {
	static Main shell ;
	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			shell= new Main(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * @param display
	 */
	public Main(final Display display) {
		super(display, SWT.SHELL_TRIM);
		setLayout(new FormLayout());
		
		Button btnMenuVentas = new Button(this, SWT.NONE);
		btnMenuVentas.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				try {
					MenuVentas m = new MenuVentas(display);
					m.open();
					
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ProxyException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		FormData fd_btnMenuVentas = new FormData();
		fd_btnMenuVentas.left = new FormAttachment(0, 100);
		fd_btnMenuVentas.right = new FormAttachment(100, -141);
		btnMenuVentas.setLayoutData(fd_btnMenuVentas);
		btnMenuVentas.setText("Menu Ventas");
		
		Button btnNewButton = new Button(this, SWT.NONE);
		fd_btnMenuVentas.bottom = new FormAttachment(100, -227);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				MainCocina m = new MainCocina(display);
				m.open();
			}
		});
		FormData fd_btnNewButton = new FormData();
		fd_btnNewButton.top = new FormAttachment(btnMenuVentas, 23);
		fd_btnNewButton.left = new FormAttachment(0, 100);
		fd_btnNewButton.right = new FormAttachment(100, -141);
		btnNewButton.setLayoutData(fd_btnNewButton);
		btnNewButton.setText("Menu Cocina");
		
		Button btnGestionDeProductos = new Button(this, SWT.NONE);
		btnGestionDeProductos.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				/*MainProductos m=null;
				try {
					m = new MainProductos(display);
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ProxyException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				m.open();
			}*/
				AgregarCategoria a = new AgregarCategoria (shell, shell.getStyle());
				a.open();
		
			}});
		FormData fd_btnGestionDeProductos = new FormData();
		fd_btnGestionDeProductos.top = new FormAttachment(btnNewButton, 23);
		fd_btnGestionDeProductos.left = new FormAttachment(0, 100);
		btnGestionDeProductos.setLayoutData(fd_btnGestionDeProductos);
		btnGestionDeProductos.setText("Configuracion de Articulos y Menu");
		
		Button button = new Button(this, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		FormData fd_button = new FormData();
		fd_button.left = new FormAttachment(0, 100);
		fd_button.right = new FormAttachment(100, -141);
		button.setLayoutData(fd_button);
		button.setText("Menu de Administrador");
		
		Button btnGestionDeClientes = new Button(this, SWT.NONE);
		fd_button.top = new FormAttachment(btnGestionDeClientes, 23);
		FormData fd_btnGestionDeClientes = new FormData();
		fd_btnGestionDeClientes.top = new FormAttachment(btnGestionDeProductos, 23);
		fd_btnGestionDeClientes.left = new FormAttachment(0, 100);
		fd_btnGestionDeClientes.right = new FormAttachment(100, -141);
		btnGestionDeClientes.setLayoutData(fd_btnGestionDeClientes);
		btnGestionDeClientes.setText("Gestion de Clientes");
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("SWT Application");
		setSize(450, 300);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
